using BEPUphysics.Entities.Prefabs;
using BEPUphysics.Entities;
using BEPUutilities;

using SoftFloat;
using BEPUphysics.CollisionRuleManagement;

namespace BEPUphysicsDemos.Demos
{
    internal class CenterOffsetDemo : StandardDemo
    {
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public CenterOffsetDemo(DemosGame game)
            : base(game)
        {
            CollisionRules.DefaultDynamicCollisionGroup = new CollisionGroup(1);

            CollisionRules.CollisionGroupRules.Clear();
            CollisionRules.CollisionGroupRules.Add(new CollisionGroupPair(CollisionRules.DefaultKinematicCollisionGroup, CollisionRules.DefaultKinematicCollisionGroup), CollisionRule.NoBroadPhase);

            //Set up two stacks which go through each other
            var firstStackGroup = new CollisionGroup(0);
            var secondStackGroup = new CollisionGroup(0);
            //Adding this rule to the space's collision group rules will prevent entities belong to these two groups from generating collision pairs with each other.
            var groupPair = new CollisionGroupPair(firstStackGroup, secondStackGroup);
            CollisionRules.CollisionGroupRules.Add(groupPair, CollisionRule.NoBroadPhase);


            var box = new Box(new NVector3(0, -5f, 0), 10, 1, 10);
            //box.CenterOffset = new NVector3(0, 0, 0);
            box.CollisionInformation.CollisionRules.Group = firstStackGroup;
            //box.CollisionInformation.CollisionRules.Personal = CollisionRule.Defer;
            World.Add(box);

            var box1 = new Box(new NVector3(0, 0, 0), 1, 3, 1, 1);
            //box.CenterOffset = new NVector3(1, 1, 0);
            box1.CollisionInformation.CollisionRules.Group = secondStackGroup;
            //box1.CollisionInformation.CollisionRules.Personal = CollisionRule.Defer;
            World.Add(box1);

            //CollisionRules.AddRule(box, box1, CollisionRule.NoBroadPhase);
            //CollisionRules.AddRule(box1, box, CollisionRule.Normal);

            box.CollisionInformation.CollisionRules.Personal = CollisionRule.Defer;

            game.Camera.Position = new NVector3(0, 0, 20);
        }

        /// <summary>
        /// Gets the name of the simulation.
        /// </summary>
        public override string Name
        {
            get { return "Center Offset Demo"; }
        }
    }
}
